<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>gh-3924</title>
    <style>
        button {
            margin-bottom: 5000px;
        }

        #footer {
            position: fixed;
            bottom: 0;
            height: 100px;
            background-color: red;
            opacity: 0.5;
            left: 0;
            right: 0;
        }
    </style>
</head>
<body>
<div id="footer"></div>
<button onclick="onClick()">Click me</button>

<script>
    window.clicked = false;

    function onClick () {
        window.clicked = true;
    }

    var button = document.querySelector('button');

    button.addEventListener('click', onClick);

    button.style.marginTop = document.documentElement.clientHeight - button.clientHeight - 20 + 'px';
</script>
</body>
</html>
